package name.huzhenbo.java.algorithm.calculation;

class Calculation {
    public static double sqr(double radicand, double precision) {
        double b = radicand / 2;
        while (Math.abs(b * b - radicand) > precision) {
            b = (b + radicand / b) / 2;
        }
        return b;
    }

    public static int pow(int base, int power) {
        if(power == 0){
            return 1;
        }else if(power % 2 == 0){
            int temp = pow(base, power / 2);
            return temp * temp;
        }else{
            return base * pow(base, power - 1);
        }
    }
}
